//
//  ZZMainTabBarViewController.m
//  Sina
//
//  Created by 张卓 on 2017/1/16.
//  Copyright © 2017年 ZZ. All rights reserved.
//

#import "ZZMainTabBarViewController.h"

@interface ZZMainTabBarViewController ()

@end

@implementation ZZMainTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self setupUI];
}

- (void)setupUI {
    
    ZZTabBar *tabBar = [[ZZTabBar alloc]init];
    [self setValue:tabBar forKey:@"tabBar"];
    
    [self addChildViewController:[self setViewControllerWith:@"ZZHomeViewController" andTitle:@"首页" andImageName:@"tabbar_home"]];
    [self addChildViewController:[self setViewControllerWith:@"ZZMessageViewController" andTitle:@"消息" andImageName:@"tabbar_message_center"]];
    [self addChildViewController:[self setViewControllerWith:@"ZZDiscoverViewController" andTitle:@"发现" andImageName:@"tabbar_discover"]];
    [self addChildViewController:[self setViewControllerWith:@"ZZProfileViewController" andTitle:@"我的" andImageName:@"tabbar_profile"]];
    
    
    
}

- (UIViewController *)setViewControllerWith:(NSString *)className andTitle:(NSString *)title andImageName:(NSString *)imageName {
    //断言.判断是否为 控制器
    Class cla = NSClassFromString(className);
    NSAssert([cla isSubclassOfClass:[UIViewController class]], @"%@",className);
    
    UIViewController *vc = [[cla alloc]init];
    vc.title = title;
    //    homeVC.tabBarController.tabBar.tintColor = [UIColor orangeColor];
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];
    
    vc.tabBarItem.image = [UIImage imageNamed:imageName] ;
    //拼接字符串
    NSString *seleImage = [NSString stringWithFormat:@"%@_selected",imageName];
    vc.tabBarItem.selectedImage = [[UIImage imageNamed:seleImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    ZZNavViewController *nav = [[ZZNavViewController alloc]initWithRootViewController:vc];
    
    return nav;
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
